package bjtu.tjj.simpledy.common;

import lombok.Data;

@Data
public class CommonResult<T> {
    private Integer code;

    private String msg;

    private T data;

    private CommonResult(ResultCode code, T data) {
        this.code = code.value;
        this.msg = code.defaultMsg;
        this.data = data;
    }

    private CommonResult(ResultCode code, String msg, T data) {
        this.code = code.value;
        this.msg = msg;
        this.data = data;
    }

    public static CommonResult<Void> success() {
        return new CommonResult<>(ResultCode.SUCCESS, null);
    }

    public static <T> CommonResult<T> success(T data) {
        return new CommonResult<>(ResultCode.SUCCESS, data);
    }

    public static CommonResult<Void> error(ResultCode code) {
        return new CommonResult<>(code, null);
    }

    public static CommonResult<Void> error(ResultCode code, String msg) {
        return new CommonResult<>(code, msg, null);
    }
}
